package com.hotel.config.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class PersonalCouponCancelDirectConfig {
    //普通交换机(个人优惠劵过期)
    public static final String NORMAL_PERSON_COUPON_CANCEL_EXCHANGE = "normal_person_coupon_cancel_exchange";
    public static final String NORMAL_PERSON_COUPON_CANCEL_QUEUE = "normal_person_coupon_cancel_queue";
    public static final String NORMAL_PERSON_COUPON_CANCEL_KEY = "normal_person_coupon_cancel_key";
    public static final String NORMAL_PERSON_COUPON_CANCEL_BEAN = "normal_person_coupon_cancel_bean";

    //死信交换机(个人优惠劵过期)
    public static final String DEAD_PERSON_COUPON_CANCEL_EXCHANGE = "dead_person_coupon_cancel_exchange";
    public static final String DEAD_PERSON_COUPON_CANCEL_QUEUE = "dead_person_coupon_cancel_queue";
    public static final String DEAD_PERSON_COUPON_CANCEL_KEY = "dead_person_coupon_cancel_key";
    public static final String DEAD_PERSON_COUPON_CANCEL_BEAN = "dead_person_coupon_cancel_bean";

    @Bean(NORMAL_PERSON_COUPON_CANCEL_EXCHANGE)
    public DirectExchange normalCancelExchange(){
        return new DirectExchange(NORMAL_PERSON_COUPON_CANCEL_EXCHANGE,true,false);
    }

    @Bean(NORMAL_PERSON_COUPON_CANCEL_QUEUE)
    public Queue normalCancelQueue(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",DEAD_PERSON_COUPON_CANCEL_EXCHANGE);
        map.put("x-dead-letter-routing-key",DEAD_PERSON_COUPON_CANCEL_KEY);
        return new Queue(NORMAL_PERSON_COUPON_CANCEL_QUEUE,true,false,false,map);
    }

    @Bean(NORMAL_PERSON_COUPON_CANCEL_BEAN)
    public Binding normalCancelBind(){
        return BindingBuilder.bind(normalCancelQueue()).to(normalCancelExchange()).with(NORMAL_PERSON_COUPON_CANCEL_KEY);
    }

    //死信交换机
    @Bean(DEAD_PERSON_COUPON_CANCEL_EXCHANGE)
    public DirectExchange deadCancelExchange(){
        return new DirectExchange(DEAD_PERSON_COUPON_CANCEL_EXCHANGE,true,false);
    }

    @Bean(DEAD_PERSON_COUPON_CANCEL_QUEUE)
    public Queue deadCancelQueue(){
        return new Queue(DEAD_PERSON_COUPON_CANCEL_QUEUE,true);
    }

    @Bean(DEAD_PERSON_COUPON_CANCEL_BEAN)
    public Binding deadCancelBind(){
        return BindingBuilder.bind(deadCancelQueue()).to(deadCancelExchange()).with(DEAD_PERSON_COUPON_CANCEL_KEY);
    }

}
